﻿using System.Windows.Forms;
using BasicFramework;
using BasicFramework.Devices.DirectX9;
using BasicFramework.Scenes;
using Demo_App.Scenes;
using SlimDX.Direct3D9;
using SlimDX;

namespace Demo_App
{
    class GameManager : BasicFramework<DX9DeviceContext>
    {
        #region Fields

        private IScene testScene;

        #endregion

        #region Properties

        #endregion

        #region Constructor


        #endregion

        #region Methods


        public override void OnInitialize()
        {
            base.OnInitialize();

            //
            // Initialize Device
            //
            DX9DeviceSettings settings = new DX9DeviceSettings
                                             {
                                                 CreationFlags = CreateFlags.SoftwareVertexProcessing,
                                                 AdapterNumber = 0
                                             };

            this.InitializeDevice(settings);

            testScene = SceneFactory.Create<IntroScene>("TestScene");

        }

        public override void OnKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            base.OnKeyDown(sender, e);

            if (e.KeyCode == Keys.Delete)
            {
                SceneManager.StopScene(testScene);
            }
            if (e.KeyCode == Keys.Insert)
            {
                SceneManager.Activate(testScene);
            }
        }

        public override void OnResourceLoad()
        {
            base.OnResourceLoad();
            DeviceContext.Device.SetRenderState(RenderState.Lighting, false);
        }

        public override void OnResourceUnload()
        {
            base.OnResourceUnload();
        }



        public override void OnRenderBegin()
        {
            base.OnRenderBegin();

            DeviceContext.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, new Color4(0.1f, 0.1f, 0.1f), 1.0f, 0);
            DeviceContext.Device.BeginScene();
        }


        public override void OnRender()
        {
            base.OnRender();
        }


        public override void OnRenderEnd()
        {
            base.OnRenderEnd();
            DeviceContext.Device.EndScene();
            DeviceContext.Device.Present();
        }
        #endregion

        #region Events

        #endregion





    }

}
